<template>

	<view class="goodsContainer">
		<view v-for="(item, index) in goodsData" :key="item.id" v-if="item.productName.includes(searchKeyword)">
			<image mode="aspectFill" :src="item.productImg"></image>
			<text class="goodsTitle">{{ item.productName }}</text>
			<text class="goodsDescription">{{ item.description }}</text>
			<text class="goodsPrice" v-if="filters.productZone !== 1">￥{{ item.price }}</text>
			<text class="goodsPrice" v-else>积分: {{ item.points }}</text>
		</view>
	</view>

</template>

<script>
	import {
		getGoods,
	} from "@/config/api.js"

	export default {
		props: {
			filters: {
				type: Object,
				default: {}
			},
			searchKeyword: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				goodsData: [{
					"description": "",
					"id": 0,
					"points": 0,
					"price": 0,
					"productImg": "",
					"productName": ""
				}],
				goodsData: [],
			};
		},
		mounted() {
			this.fetchGoods()
		},
		methods: {
			async fetchGoods() {
				var res = await getGoods(this.filters)
				this.goodsData = res
			}
		}
	}
</script>

<style>
	.goodsContainer {
		display: flex;
		flex-wrap: wrap;
		padding: 4px;
	}

	.goodsContainer>view {
		display: flex;
		flex-flow: column;
		width: calc(50% - 8px);
		margin: 4px;
		box-sizing: border-box;
		border-radius: 8px;
		overflow: hidden;
		background-color: #f6f6f6;
	}

	.goodsContainer>view>image {
		width: 100%;
		height: calc(50vw - 8px);
	}

	.goodsTitle {
		padding: 8px 8px 4px;
	}

	.goodsDescription {
		color: #777;
		font-size: 12px;
		padding: 0 8px;
	}

	.goodsPrice {
		color: red;
		padding: 4px 8px 8px;

	}
</style>